//
// Created by zhouwd on 2019/7/2.
//

#include "x265-encode.h"


int X265ENCODE::init() {
    x264_param_default(&param);

    param.i_width  = 720;
    param.i_height = 1080;
    /*
    //Param
    param.i_log_level  = X264_LOG_DEBUG;
    param.i_threads  = X264_SYNC_LOOKAHEAD_AUTO;
    param.i_frame_total = 0;
    param.i_keyint_max = 10;
    param.i_bframe  = 5;
    param.b_open_gop  = 0;
    param.i_bframe_pyramid = 0;
    param.rc.i_qp_constant=0;
    param.rc.i_qp_max=0;
    param.rc.i_qp_min=0;
    param.i_bframe_adaptive = X264_B_ADAPT_TRELLIS;
    param.i_fps_den  = 1;
    param.i_fps_num  = 25;
    param.i_timebase_den = param.i_fps_num;
    param.i_timebase_num = param.i_fps_den;
    */
    param.i_csp = X264_CSP_YV12;
    param.b_repeat_headers = 1;
    param.b_annexb = 1;

    x264_param_apply_profile(&param, x264_profile_names[2]);

    pic_in = (x264_picture_t*)malloc(sizeof(x264_picture_t));
    if (pic_in == NULL)
    {

        return -1;
    }
    pic_out = (x264_picture_t*)malloc(sizeof(x264_picture_t));
    if (pic_out == NULL)
    {

        return -2;
    }
    x264_picture_init(pic_out);
    x264_picture_alloc(pic_in, X264_CSP_YV12, param.i_width, param.i_height);

    handle = x264_encoder_open(&param);



    return 0;
}

int X265ENCODE::encode() {

    int i_nal;

    int i_frame_size = 0;

    //pic_in->img.plane

    i_frame_size = x264_encoder_encode(handle, &nal, &i_nal, pic_in, pic_out);

    if(i_frame_size){



    }


    return 0;
}
